package com.item.yxlottery.yxlottery.adapter;

/*
 *------------------------------
 * @创建者      Administrator
 * @创建时间    2016/12/24 17:03
 * @文件描述    
 *------------------------------
 */

import android.text.SpannableString;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.item.yxlottery.yxlottery.R;
import com.item.yxlottery.yxlottery.bean.BuySsqBean;
import com.item.yxlottery.yxlottery.utils.RedNumberUtil;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class BuySsqAdapter extends BaseQuickAdapter<BuySsqBean, BaseViewHolder> {

    private List mdata;

    public BuySsqAdapter(int layoutResId, List<BuySsqBean> data) {
        super(layoutResId, data);
        mdata = data;
    }

    @Override
    protected void convert(BaseViewHolder helper, BuySsqBean bean) {
        String[] redBalls = bean.getRed().split(",");
        String[] blueBalls = bean.getBlue().split(",");
        ArrayList<Integer> redList = new ArrayList<>();
        ArrayList<Integer> blueList = new ArrayList<>();
        for (String red : redBalls) {
            redList.add(Integer.parseInt(red));
        }
        for (String blue : blueBalls) {
            blueList.add(Integer.parseInt(blue));
        }
        Collections.sort(redList);
        Collections.sort(blueList);
        StringBuffer redBuffer = new StringBuffer();
        StringBuffer blueBuffer = new StringBuffer();
        for (Integer red : redList) {
            if (red < 10) {
                redBuffer.append("0" + red + "   ");
            } else {
                redBuffer.append(red + "   ");
            }
        }
        for (Integer blue : blueList) {
            if (blue < 10) {
                blueBuffer.append("0" + blue + "   ");
            } else {
                blueBuffer.append(blue + "   ");
            }
        }
        SpannableString ss = RedNumberUtil.setRedAndBlueColor(redBuffer.toString() + "|   " + blueBuffer.toString(), 0xffff0000, "|", 0xff737373, 0xff0000ff);
        helper.setText(R.id.tv_item_buyssq_ball, ss).addOnClickListener(R.id.iv_item_buyssq_cancel);
        if (helper.getAdapterPosition() == 0) {
            helper.getView(R.id.view_item_buyssq_line).setVisibility(View.GONE);
        } else {
            helper.getView(R.id.view_item_buyssq_line).setVisibility(View.VISIBLE);
        }
    }
}
